#ifndef __COMM_TOOLS_H
#define __COMM_TOOLS_H

#include "t_types.h"

typedef struct _COMM_TIME_S
{
	unsigned int unYear;
	unsigned int unMon;
	unsigned int unDayOfMon;
	unsigned int unHour;
	unsigned int unMin;
	unsigned int unSec;
} COMM_TIME_S;

static inline int ToBCD4(T_UINT32 u32Value, char *pBCD)
{
	if(pBCD == NULL)
	{
		return -1;
	}
	pBCD[0] = u32Value/1000;
	pBCD[1] = u32Value%1000/100;
	pBCD[2] = u32Value%100/10;
	pBCD[3] = u32Value%10;
		
	return 0;	
}

static inline int ToBCD2(T_UINT32 u32Value, char *pBCD)
{
	if(pBCD == NULL)
	{
		return -1;
	}
	pBCD[0] = u32Value%100/10;
	pBCD[1] = u32Value%10;
		
	return 0;	
}

static inline int ToBCD4_packet(T_UINT32 u32Value, char *pBCD)
{
	if(pBCD == NULL)
	{
		return -1;
	}
	pBCD[0] = (((u32Value/1000) << 4) & 0xf0) | ((u32Value%1000/100) & 0x0f);
	pBCD[1] = (((u32Value%100/10) << 4) & 0xf0) | ((u32Value%10) & 0x0f);
		
	return 0;	
}

static inline int ToBCD2_packet(T_UINT32 u32Value, char *pBCD)
{
	if(pBCD == NULL)
	{
		return -1;
	}

	pBCD[0] = (((u32Value%100/10) << 4) & 0xf0) | ((u32Value%10) & 0x0f);
		
	return 0;	
}
T_INT32 COMM_GetFileSize(T_CHAR *pcFile);
T_INT32 COMM_GetTime(COMM_TIME_S *pstTime);
T_INT32 COMM_GetDateTimeBCD6(T_UINT8 *pDateTime);
T_INT32 COMM_SpecialBinStreamConvert_Decode(T_UINT8 *pu8In, T_INT32 s32InLen, T_UINT8 *pu8Out, T_INT32 *ps32OutLen);
T_INT32 COMM_SpecialBinStreamConvert_Encode(T_UINT8 *pu8In, T_INT32 s32InLen, T_UINT8 *pu8Out, T_INT32 *ps32OutLen);
long COMM_HostToNetL(long host);
long COMM_NetToHostL(long net);
unsigned short COMM_HostToNetS(unsigned short host);
unsigned short COMM_NetToHostS(unsigned short net);


#endif
